<!-- 运输单签收 -->
<template>
  <el-dialog
    title="签收"
    :visible.sync="dialogVisible"
    append-to-body
    width="40%"
  >
    <avue-form
      ref="form"
      v-loading="loading"
      v-model="form"
      :option="option"
    ></avue-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">关 闭</el-button>
      <el-button type="primary" v-noMoreClick @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { signForReceipt } from "@/api/transportation/demandorder";
export default {
  data() {
    var checkNum = (rule, value, callback) => {
      if (value && value > 50) {
        callback(new Error("请输入正确的签收数量,签收数量最大限度为50吨"));
      } else {
        callback();
      }
    };
    return {
      dialogVisible: false,
      loading: false,
      form: {}, //签收信息
      parentId: "", //运单id
      option: {
        labelWidth: 130,
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "签收数量（吨）",
            prop: "num",
            type: "number",
            span: 24,
            rules: [
              {
                required: true,
                message: "请输入签收数量",
                trigger: ["blur", "change"],
              },
              { validator: checkNum, trigger: ["blur", "change"] },
            ],
          },
          {
            label: "签收单上传",
            prop: "signPic",
            type: "upload",
            span: 24,
            listType: "picture-img",
            propsHttp: {
              res: "data",
              name: "originalName",
              url: "link",
            },
            action: "/api/blade-resource/oss/endpoint/put-file-attach",
            rules: [
              {
                required: true,
                message: "请上传签收单",
                trigger: "change",
              },
            ],
          },
          {
            label: "交付检查表上传",
            prop: "overPic",
            type: "upload",
            span: 24,
            listType: "picture-img",
            propsHttp: {
              res: "data",
              name: "originalName",
              url: "link",
            },
            action: "/api/blade-resource/oss/endpoint/put-file-attach",
            rules: [
              {
                required: true,
                message: "请上传交付检查表",
                trigger: "change",
              },
            ],
          },
          {
            label: "备注",
            prop: "remark",
            span: 24,
          },
        ],
      },
    };
  },
  components: {},
  computed: {},
  methods: {
    open(id) {
      this.dialogVisible = true;
      this.form = {};
      this.parentId = id;
      this.$nextTick(() => {
        this.$refs.form.resetForm();
      });
    },
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.loading = true;
          signForReceipt({ ...this.form, parentId: this.parentId }).then(
            () => {
              this.loading = false;
              this.dialogVisible = false;
              this.$refs.form.allDisabled = false;
              this.$refs.form.resetForm();
              this.$emit("refresh");
              this.$message({
                type: "success",
                message: "操作成功!",
              });
            },
            (error) => {
              window.console.log(error);
              this.loading = false;
              this.$refs.form.allDisabled = false;
            }
          );
        } else {
          this.$message({
            message: "请填写必填项",
            type: "error",
          });
          return false;
        }
      });
    },
  },
};
</script>

<style></style>
